//
//  FQDColumnCenterViewController.m
//  FakeQDaily
//
//  Created by mewxiv on 9/20/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDColumnCenterViewController.h"
#import "FQDMySubscriptionViewController.h"
#import "FQDAllColumnsViewController.h"
#import "FQDNavigationView.h"
#import "FQDTabbedPageView.h"
#import "FQDSegmentedControl.h"

#import "Masonry.h"

@interface FQDColumnCenterViewController () <FQDMySubscriptionViewControllerDelegate>

@property (nonatomic, strong) FQDNavigationView *navView;
@property (nonatomic, strong) FQDTabbedPageView *pageView;

@end

@implementation FQDColumnCenterViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupNavigationView];
    [self setupTabViews];
}

- (void)setupNavigationView
{
    self.navView = [[FQDNavigationView alloc] init];
    self.navView.titleLabel.text = @"栏目中心";
    self.navView.showBlurBg = YES;
    [self.navView.backButton addTarget:self action:@selector(popBack:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.navView];
    
    WeakSelf;
    [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.and.right.equalTo(weakSelf.view);
        make.height.equalTo(@64);
    }];
}

- (void)setupTabViews
{
    self.pageView = [[FQDTabbedPageView alloc] init];
    self.pageView.segmentedControl.selectIndicatorFixedWidthRatio = 0.5f;
    [self.view addSubview:self.pageView];
    
    FQDMySubscriptionViewController *msVC = [[FQDMySubscriptionViewController alloc] init];
    msVC.delegate = self;
    [self addChildViewController:msVC];
    [self.pageView addPage:msVC.view withTitle:@"我的订阅"];
    
    FQDAllColumnsViewController *acVC = [[FQDAllColumnsViewController alloc] init];
    [self addChildViewController:acVC];
    [self.pageView addPage:acVC.view withTitle:@"所有栏目"];
    
    WeakSelf;
    [self.pageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.navView.mas_bottom);
        make.left.right.and.bottom.equalTo(weakSelf.view);
    }];
}

- (void)gotoAllColumnsView
{
    self.pageView.segmentedControl.selectedSegmentIndex = 1;
}

- (void)popBack:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

#pragma mark - FQDMySubscriptionViewControllerDelegate
- (void)subscriptionViewController:(UIViewController *)viewController didClickedMoreColumnsButton:(UIButton *)button
{
    [self gotoAllColumnsView];
}

@end
